﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class MyResolution : MonoBehaviour
{
    public InputField input1;
    public InputField input2;
    public InputField input3;
    public InputField input4;
    public Text text;
    public Toggle isFullScreen;
    public Slider slider;

    private void Start()
    {
        input1.text = Display.main.renderingWidth.ToString();
        input2.text = Display.main.renderingHeight.ToString();
        input3.text = Display.main.systemWidth.ToString();
        input4.text = Display.main.systemHeight.ToString();

        slider.maxValue = 2;
        slider.minValue = 0.00001f;
        slider.value = Camera.main.aspect;
        slider.onValueChanged.AddListener((value) => Camera.main.aspect = value);

    }

    void Update()
    {
        // 设置 屏幕分辨率
        if (Input.GetKeyDown(KeyCode.P))
        {
            int x = int.Parse(input1.text);
            int y = int.Parse(input2.text);
            Screen.SetResolution(x, y, isFullScreen.isOn);
            text.text = $"X: {x} , Y : {y}";
        }

        // 按O全屏  
        if (Input.GetKeyDown(KeyCode.O))
        {
            //获取设置当前屏幕分辩率  
            Resolution[] resolutions = Screen.resolutions;
            //设置当前分辨率  
            Screen.SetResolution(resolutions[resolutions.Length - 1].width, resolutions[resolutions.Length - 1].height, true);

            Screen.fullScreen = true;  //设置成全屏,  

            text.text = resolutions[resolutions.Length - 1].ToString();
        }

        if (Input.GetKeyDown(KeyCode.I))
        {
            int w = int.Parse(input1.text);
            int h = int.Parse(input2.text);
            int x = int.Parse(input3.text);
            int y = int.Parse(input4.text);
            Display.displays[0].Activate();
            Display.main.SetRenderingResolution(w, h);
            //Display.main.SetParams(w, h, x, y);
            text.text = $"{Display.displays[0]}:        X: {Display.displays[0].renderingWidth}, Y: {Display.displays[0].renderingHeight} \n" +
                        $"{Display.main}:        X: {Display.displays[0].systemWidth}, Y: {Display.displays[0].systemHeight}";
            //Display.displays[1].Activate();
            //Display.main.SetRenderingResolution(w, h);
        }
        if (Input.GetKeyDown(KeyCode.U))
        {
            string str = $"数量：{Screen.resolutions.Length} \n";

            foreach (var item in Screen.resolutions)
            {
                str += item.ToString() + " 、";
            }

            str +=  "\n\n当前分辨率： " + Screen.currentResolution;

            str +=  "\n\ndpi： " + Screen.dpi;

            text.text = str;
        }
    }

}